package top.v5it.japi.ddd.example.account.service.impl;

import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.v5it.japi.ddd.core.dao.impl.BasicDaoJdbcImpl;
import top.v5it.japi.ddd.core.service.impl.BasicServiceImpl;
import top.v5it.japi.ddd.example.account.entity.Account;
import top.v5it.japi.ddd.example.account.service.AccountService;

import java.util.List;

/**
 * @author zhanpu
 * @date 2023/3/9
 */
@Service("accountService")
@Slf4j
public class AccountServiceImpl extends BasicServiceImpl<BasicDaoJdbcImpl> implements AccountService {

    @Override
    public Account searchById(Long id) {
        Assert.notNull(id, "请求id不能为空");
        return basicDao.load(id, new Account());
    }

    @Override
    public void modify(Account entity) {
        Assert.notNull(entity, "请求参数[entity]不能为空");
        basicDao.update(entity);
    }

    @Override
    public void add(Account entity) {
        Assert.notNull(entity, "请求参数[entity]不能为空");
        basicDao.insert(entity);
    }

    @Override
    public void batch(List<Account> accounts) {
        basicDao.insertOrUpdateForList(accounts);
    }

    @Override
    public void test(Account account, String mode) {
        log.info("{}, {}", account, mode);
    }
}
